package org.tabcap.gui.menu.help;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import org.tabcap.TCInstance;

import static java.awt.event.KeyEvent.*;

public class TCHelpMenu extends JMenu
{
	private static final long serialVersionUID = -5025706726629036744L;
	
	public TCHelpMenu(TCInstance manager)
	{
		super("Help");
		
		addOption("Open Help", manager.helpAction(), VK_F1);
		addOption("Visit Website", manager.webAction());
		addSeparator();
		addOption("About TABCAP", manager.aboutAction());
	}
	
	public void addOption(String name, ActionListener listener)
	{
		JMenuItem option = new JMenuItem(name);
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, int keyID)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyID, 0));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, int keyID, int modifiers)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyID, modifiers));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
	
	public void addOption(String name, ActionListener listener, Character keyChar, int modifiers)
	{
		JMenuItem option = new JMenuItem(name);
		option.setAccelerator(KeyStroke.getKeyStroke(keyChar, modifiers));
		if(listener != null)
			option.addActionListener(listener);
		add(option);
	}
}